import java.util.Arrays;
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();//数组个数
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        getResult(nums);
    }

    public static void getResult(int[] nums){
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]/10==0&&nums[i]%2==1)
                nums[i] = -1;//判定为个位数且为单数
            if(nums[i] %2 == 1){
                // 判定为单数 直接将第一个遇到的双数和最后一个数进行替换
                nums[i] = changeNumber(nums[i]);
            }
        }

        for (int i = 0; i < nums.length; i++) {
            System.out.println(nums[i]);
        }
    }

    public static int changeNumber(int num){
        //先转换为字符串?
        String str = String.valueOf(num);
        char[] chars = str.toCharArray();
        int length = chars.length;
        for (int i = 0; i < length; i++) {
            if(chars[i]=='2'||chars[i]=='4'||chars[i]=='6'||chars[i]=='8') {
                char ch = chars[i];
                chars[i] = chars[length-1];
                chars[length-1] = ch;
                // 再次转换为数字
                return Integer.parseInt(String.copyValueOf(chars));
            }
        }
        return -1;
    }
}
